# Build recipe for notmuch
#
# Copyright 2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=notmuch
version=0.25
release=1

description="
Notmuch -- Just an email system
"

homepage=https://notmuchmail.org/
license=GPLv3+

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch="https://notmuchmail.org/releases/${tarname}"

# Source documentation
docs="AUTHORS COPYING* NEWS README*"

build() {
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
    $configure_args \
    --libdir=/usr/lib${libSuffix} \
    --mandir=$mandir \
    --docdir=$docdir \
    --build="$(cc -dumpmachine)" \
    --without-ruby

    make -j${jobs}
    make -j${jobs} install DESTDIR="$destdir"

    # Compress manual pages
    if [ -d "${destdir}/$mandir" ] ; then
	(
            cd "${destdir}/$mandir"
	    find . -type f -exec lzip -9 '{}' +
	    find . -type l | while read -r file
	    do
		ln -sf "$(readlink -- "$file").lz" "${file}.lz"
		rm -- "$file"
	    done
	)
    fi

    # Copy documentation
    mkdir -p "${destdir}/usr/local/share/doc/${program}-${version}"
    cp -p $docs "${destdir}/usr/local/share/doc/${program}-${version}/"
}
